Post a message to an incoming webhook

Completed

With connectors and Incoming Webhooks, you can send messages by posting a JSON payload to the webhook URL. In this unit, you will learn how to create messages to send to incoming webhooks.

Actionable messages

You can create actionable messages to send through Incoming Webhooks or connectors. Actionable messages allow users to take action without leaving their email client, increasing user engagement.

The actionable messages include six visible buttons on the card. Each button is defined in the potentialAction property of the message by using ActionCard actions, each with an input type, a text field, a date picker, or a multiple-choice list. Each ActionCard has an associated action, for example HttpPOST.

The connector cards support the following actions:

  • ActionCard: Presents one or more input types and associated actions.
  • HttpPOST: Sends POST request to a URL.
  • OpenUri: Opens URI in a separate browser or app. Optionally, targets different URIs based on operating systems.

The ActionCard action supports three input types:

  • TextInput: A single line or multiline text field with an optional length limit.
  • DateInput: A date selector with an optional time selector.
  • MultichoiceInput: An enumerated list of choices offering either a single selection or multiple selections.

MultichoiceInput supports a style property that controls whether the list initially appears fully expanded. The default value of style depends on the value of isMultiSelect as follows:

isMultiSelect default style
false or not specified compact
true expanded

To display the multiple-selection list in the compact style, specify "isMultiSelect": true and "style": true.

Send a message through Incoming Webhook or connector for Microsoft 365 Groups

To send a message through your Incoming Webhook or connector for Microsoft 365 Groups, post a JSON payload to the webhook URL.

You can also use this JSON to create cards containing rich inputs, such as text entry, multiselect, or selecting date and time. The code that generates the card and posts it to the webhook URL can run on any hosted service. These cards are defined as part of actionable messages and are also supported in cards used in Teams bots and message extensions.

Here's an example of a message:

{
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "themeColor": "0076D7",
    "summary": "Larry Bryant created a new task",
    "sections": [{
        "activityTitle": "Larry Bryant created a new task",
        "activitySubtitle": "On Project Tango",
        "activityImage": "https://adaptivecards.io/content/cats/3.png",
        "facts": [{
            "name": "Assigned to",
            "value": "Unassigned"
        }, {
            "name": "Due date",
            "value": "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)"
        }, {
            "name": "Status",
            "value": "Not started"
        }],
        "markdown": true
    }],
    "potentialAction": [{
        "@type": "ActionCard",
        "name": "Add a comment",
        "inputs": [{
            "@type": "TextInput",
            "id": "comment",
            "isMultiline": false,
            "title": "Add a comment here for this task"
        }],
        "actions": [{
            "@type": "HttpPOST",
            "name": "Add comment",
            "target": "https://learn.microsoft.com/outlook/actionable-messages"
        }]
    }, {
        "@type": "ActionCard",
        "name": "Set due date",
        "inputs": [{
            "@type": "DateInput",
            "id": "dueDate",
            "title": "Enter a due date for this task"
        }],
        "actions": [{
            "@type": "HttpPOST",
            "name": "Save",
            "target": "https://learn.microsoft.com/outlook/actionable-messages"
        }]
    }, {
        "@type": "OpenUri",
        "name": "Learn More",
        "targets": [{
            "os": "default",
            "uri": "https://learn.microsoft.com/outlook/actionable-messages"
        }]
    }, {
        "@type": "ActionCard",
        "name": "Change status",
        "inputs": [{
            "@type": "MultichoiceInput",
            "id": "list",
            "title": "Select a status",
            "isMultiSelect": "false",
            "choices": [{
                "display": "In Progress",
                "value": "1"
            }, {
                "display": "Active",
                "value": "2"
            }, {
                "display": "Closed",
                "value": "3"
            }]
        }],
        "actions": [{
            "@type": "HttpPOST",
            "name": "Save",
            "target": "https://learn.microsoft.com/outlook/actionable-messages"
        }]
    }]
}

Send Adaptive Cards using an Incoming Webhook

You can also send Adaptive Cards.

Here's an example of an Adaptive Card message:

{
   "type":"message",
   "attachments":[
      {
         "contentType":"application/vnd.microsoft.card.adaptive",
         "contentUrl":null,
         "content":{
            "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
            "type":"AdaptiveCard",
            "version":"1.2",
            "body":[
                {
                "type": "TextBlock",
                "text": "For Samples and Templates, see [https://adaptivecards.io/samples](https://adaptivecards.io/samples)"
                }
            ]
         }
      }
   ]
}

The properties for Adaptive Card JSON file are as follows:

  • The "type" field must be "message".
  • The "attachments" array contains a set of card objects.
  • The "contentType" field must be set to Adaptive Card type.
  • The "content" object is the card formatted in JSON.

Code samples of Adaptive Cards are available for testing.

Test your incoming webhook

Test your incoming webhook by sending HTTP messages to the webhook endpoint.

You can send messages using tools like Postman, cURL, and PowerShell.

For example, from PowerShell, you could use the following command to send a "Hello World!" message to a webhook endpoint:

Invoke-RestMethod -Method post -ContentType 'Application/Json' -Body '{"text":"Hello World!"}' -Uri <YOUR WEBHOOK URL>

After sending the message, using your webhook URL, you should be able to verify that a new message has been posted to the channel.